package com.java2207.group1.controller;

import com.java2207.group1.common.LayuiPageVo;
import com.java2207.group1.common.R;
import com.java2207.group1.pojo.Food;
import com.java2207.group1.service.FoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;

/**
 * @author lz
 * @Date 2022/7/26 14:37
 */
@RestController
@RequestMapping("/food")
public class FoodController {

    @Autowired
    private FoodService foodService;

    @RequestMapping("/foodList")
    public LayuiPageVo<Food> foodList(@RequestParam Map<String, Food> params){
        LayuiPageVo<Food> food = foodService.foodList(params);
        return food;
    }

    @RequestMapping("/updateFood")
    public R updateFood(Food food){
        int result = foodService.updateFood(food);
        if(result == 1){
            return R.ok();
        }
        return R.error();
    }


    @RequestMapping("/addFood")
    public R addFood(Food food){
        int result = foodService.addFood(food);
        if(result == 1){
            return R.ok();
        }
        return R.error();
    }


    @RequestMapping("/deleteFood")
    public R deleteFood(Integer id){
        int result = foodService.deleteFood(id);
        if(result == 1){
            return R.ok();
        }
        return R.error();
    }

}
